name: PR merge/close notification
on:
  pull_request:
    types: [ closed ]

jobs:

  merge_job:
    if: github.event.pull_request.merged == true
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@master
      - name: send custom message with args
        uses: appleboy/telegram-action@master
        with:
          to: ${{ secrets.CHAT_ID }}
          token: ${{ secrets.TELEGRAM_TOKEN }}
          message: "${{ github.event.repository.name }}: 
          the ${{ github.event_name }} '${{ github.event.pull_request.title }}' 
          (#${{ github.event.number }}) was merged.
          \n[Link](${{ github.event.pull_request.html_url }}).
          \nDescription:\n${{ github.event.pull_request.body }}
          \n
          \nCheck it out to keep your local repository updated."
          format: markdown
          disable_web_page_preview: true


  close_job:
    if: github.event.pull_request.merged == false
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@master
      - name: send custom message with args
        uses: appleboy/telegram-action@master
        with:
          to: ${{ secrets.CHAT_ID }}
          token: ${{ secrets.TELEGRAM_TOKEN }}
          message: "${{ github.event.repository.name }}: 
          the ${{ github.event_name }} ${{ github.event.pull_request.title }} 
          (${{ github.event.number }}) was closed."
